package com.libraryApp.controller;

import com.libraryApp.appUtil.TokenToUser;
import com.libraryApp.entity.BookDo;
import com.libraryApp.entity.UserDo;
import com.libraryApp.service.AppBookService;
import com.libraryManage.commons.utils.ResponseEntity;
import com.libraryManage.commons.utils.SimpleResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @CreateDate 2021-03-14
 * @Author yufang
 */

@Api(tags={"app图书接口"})
@RestController
@CrossOrigin
@RequestMapping("/app/books")
public class AppBookController {

    @Autowired
    AppBookService appBookService;

    @ApiOperation("图书搜索")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/searchBook" , method = RequestMethod.GET)
    public ResponseEntity<List<BookDo>> searchBook(int pageNumber,int bookCategoryId, String keyword, String searchType){

        return appBookService.searchBook(pageNumber,bookCategoryId,keyword,searchType);

    }

    @ApiOperation("获取热门图书")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/hotBook" , method = RequestMethod.GET)
    public ResponseEntity<List<BookDo>> getHotBook(){

        return appBookService.getHotBook();

    }

    @ApiOperation("获取图书详情")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/bookData" , method = RequestMethod.GET)
    public ResponseEntity<BookDo> getBookData(int bookId){

        return appBookService.getBookData(bookId);

    }

    @ApiOperation("加入书架")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/addBookshelf" , method = RequestMethod.GET)
    public SimpleResp addBookshelf(@TokenToUser UserDo userDo, int bookId){

        return appBookService.addBookshelf(bookId,userDo);

    }

    @ApiOperation("预约借阅图书接口")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/borrowBook" , method = RequestMethod.GET)
    public SimpleResp borrowBook(@TokenToUser UserDo userDo,int bookId){

        return appBookService.borrowBook(userDo.getUserId(),bookId);

    }

}
